<?php
namespace app\common\controller;

use think\Controller;
use think\Request;
use app\common\model\Business\Business;
use app\common\library\util\Token;
use think\Cookie;

class Home extends Controller{
    public $noLogin = [];
    protected $business = null;
    public function __construct(Request $request)
    {
        parent::__construct();
        // halt($request->action());
        if(in_array('*',$this->noLogin)==in_array($request->action(),$this->noLogin)){
            $this->isLogin($request);
        }
        // 1 0 0
        // 1 1 1
        // 0 0 1
        // 0 1 0
    }
    public function isLogin(Request $request){
        $token = Cookie::get('token');
        if(!$token){
            $this->error("token出错","/home/index/login");
        }
        // halt($token);
        $status = Token::checkToken($token);
        // halt($status);
        if($status["code"]==1){
            $this->business = Business::where("id",$status["data"]["id"])->find();
            if($this->business['mobile']==$status["data"]["mobile"]){
                // halt($business['nickname']);
                $this->assign('business',$this->business);
                return;
            }else{
                $this->error("token出错","/home/index/login");
            }
        }else{
            $this->error($status["msg"],"/home/index/login");
        }
    }
}